New Notebook

In [23]:

    # Save project before running this
    aprx = arcpy.mp.ArcGISProject("CURRENT")

In [24]:

    # Show list of maps
    aprx.listMaps()
    i=0
    for mp in aprx.listMaps():
        print( str(i)+": "+mp.name)
        i=i+1

    0: Map

In [25]:

    # Select the Map you want to work with
    Select = 0
    mpr = aprx.listMaps()[Select]

In [26]:

    # Show list of Layers
    i=0
    for m in mpr.listLayers():
        print( str(i) + ": "+ m.name )
        i=i+1

    0: Depth (High)
    1: Depth (Low)
    2: Depth (Medium)
    3: Velocity (High)
    4: Velocity (Low)
    5: Velocity (Medium)
    6: WSE (High)
    7: WSE (Low)
    8: WSE (Medium)
    9: Ground Elevation
    10: World Hillshade
    11: World Topographic Map

In [27]:

    # Select the boundaries of the layers to be changed
    unvis0 = 0
    unvis1 = 8

In [28]:

    # Show list of layouts
    aprx.listLayouts()
    i=0
    for ly in aprx.listLayouts():
        print(str(i)+": "+ly.name)
        i=i+1

    0: Velocity
    1: WSE
    2: Depth

In [29]:

    # Don't change anything in this function unless you know what are you doing
    # But run the cell to define the function
    def onlyvis(mpr,novis0,novis1,vis):
        # Makes everything invisible from novis0 to novis1 then makes vis visible in the mpr map
        i=novis0
        for m in mpr.listLayers()[novis0:novis1]:
            m.visible = False
            if (novis0==vis):
                print( str(i)+": "+m.name)
            i=i+1

        mpr.listLayers()[vis].visible = True

In [30]:

    # Fill the list with the saving path, must be a raw string define as r"STRING"
    # Remember it must match the position shown on cell 6.
    pathto = [
        r"C:\temp\DPT_High.png",
        r"C:\temp\DPT_Low-.png",
        r"C:\temp\DPT_Medi.png",
        r"C:\temp\VEL_High.png",
        r"C:\temp\VEL_Low-.png",
        r"C:\temp\VEL_Medi.png",
        r"C:\temp\WSE_High.png",
        r"C:\temp\WSE_Low-.png",
        r"C:\temp\WSE_Medi.png"
    ]

In [31]:

    # Create a vector with what layout each variable will be using
    # In this example 0 is Velocity, 1 is WSE and 2 is Depth as per cell 8.
    # It must match the position of the cell 6

    layoutsel = [0,0,0,2,2,2,1,1,1]

In [32]:

    for j in range(len(layoutsel)):
        # Select layout from layoutsel
        lyd = aprx.listLayouts()[layoutsel[j]]
        exppath = pathto[j]
        # Change map to only visible
        onlyvis(mpr,unvis0,unvis1+1,j+unvis0)
        # Export
        print("Exporting : "+str(j)+" : "+exppath)
        lyd.exportToPNG(exppath,resolution = 300)
    print("FINISHED")

    0: Depth (High)
    1: Depth (Low)
    2: Depth (Medium)
    3: Velocity (High)
    4: Velocity (Low)
    5: Velocity (Medium)
    6: WSE (High)
    7: WSE (Low)
    8: WSE (Medium)
    Exporting : 0 : C:\temp\DPT_High.png
    Exporting : 1 : C:\temp\DPT_Low-.png
    Exporting : 2 : C:\temp\DPT_Medi.png
    Exporting : 3 : C:\temp\VEL_High.png
    Exporting : 4 : C:\temp\VEL_Low-.png
    Exporting : 5 : C:\temp\VEL_Medi.png
    Exporting : 6 : C:\temp\WSE_High.png
    Exporting : 7 : C:\temp\WSE_Low-.png
    Exporting : 8 : C:\temp\WSE_Medi.png
    FINISHED